<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs">
<head>
<title>std::signal</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">
<link rel="shortcut icon" href="../../../../common/favicon.ico">
<link rel="stylesheet" href="../../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-css:7:15cea3ec788a65b5187d4018eed543bf */</style>

<script src="../../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"cpp/utility/program/signal","wgTitle":"cpp/utility/program/signal","wgCurRevisionId":53471,"wgArticleId":848,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgBreakFrames":false,"wgPageContentLanguage":"zh","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"zh","wgMonthNames":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgMonthNamesShort":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgRelevantPageName":"cpp/utility/program/signal","wgUserVariant":"zh","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"zh","language":"zh","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-MathJax":1,"gadget-ColiruCompiler":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-js:7:258d7cd6aa9aa67dee25e01fb6a9e505 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-cpp {line-height: normal;}
.source-cpp li, .source-cpp pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for cpp
 * CSS class: source-cpp, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.cpp.source-cpp .de1, .cpp.source-cpp .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.cpp.source-cpp  {font-family:monospace;}
.cpp.source-cpp .imp {font-weight: bold; color: red;}
.cpp.source-cpp li, .cpp.source-cpp .li1 {font-weight: normal; vertical-align:top;}
.cpp.source-cpp .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.cpp.source-cpp .li2 {font-weight: bold; vertical-align:top;}
.cpp.source-cpp .kw1 {color: #0000dd;}
.cpp.source-cpp .kw2 {color: #0000ff;}
.cpp.source-cpp .kw3 {color: #0000dd;}
.cpp.source-cpp .kw4 {color: #0000ff;}
.cpp.source-cpp .co1 {color: #909090;}
.cpp.source-cpp .co2 {color: #339900;}
.cpp.source-cpp .coMULTI {color: #ff0000; font-style: italic;}
.cpp.source-cpp .es0 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es1 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es2 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es3 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es4 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es5 {color: #008000; font-weight: bold;}
.cpp.source-cpp .br0 {color: #008000;}
.cpp.source-cpp .sy0 {color: #008000;}
.cpp.source-cpp .sy1 {color: #000080;}
.cpp.source-cpp .sy2 {color: #000040;}
.cpp.source-cpp .sy3 {color: #000040;}
.cpp.source-cpp .sy4 {color: #008080;}
.cpp.source-cpp .st0 {color: #008000;}
.cpp.source-cpp .nu0 {color: #000080;}
.cpp.source-cpp .nu6 {color: #000080;}
.cpp.source-cpp .nu8 {color: #000080;}
.cpp.source-cpp .nu12 {color: #000080;}
.cpp.source-cpp .nu16 {color:#000080;}
.cpp.source-cpp .nu17 {color:#000080;}
.cpp.source-cpp .nu18 {color:#000080;}
.cpp.source-cpp .nu19 {color:#000080;}
.cpp.source-cpp .ln-xtra, .cpp.source-cpp li.ln-xtra, .cpp.source-cpp div.ln-xtra {background-color: #ffc;}
.cpp.source-cpp span.xtra { display:block; }

/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-text {line-height: normal;}
.source-text li, .source-text pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for text
 * CSS class: source-text, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.text.source-text .de1, .text.source-text .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.text.source-text  {font-family:monospace;}
.text.source-text .imp {font-weight: bold; color: red;}
.text.source-text li, .text.source-text .li1 {font-weight: normal; vertical-align:top;}
.text.source-text .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.text.source-text .li2 {font-weight: bold; vertical-align:top;}
.text.source-text .ln-xtra, .text.source-text li.ln-xtra, .text.source-text div.ln-xtra {background-color: #ffc;}
.text.source-text span.xtra { display:block; }

/*]]>*/
</style><!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_utility_program_signal skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        <!-- /header -->
        <!-- content -->
<div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::</span>signal</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">来自cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../../cpp.html" title="cpp">cpp</a>‎ | <a href="../../utility.html" title="cpp/utility">utility</a>‎ | <a href="../program.html" title="cpp/utility/program">program</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr"><div class="t-navbar" style=""><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../../cpp.html" title="cpp"> C++</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../../language.html" title="cpp/language">语言</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../header.html" title="cpp/header">标准库头文件</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../freestanding.html" title="cpp/freestanding"> 自立与有宿主实现</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../named_req.html" title="cpp/named req">具名要求</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../utility.html#.E8.AF.AD.E8.A8.80.E6.94.AF.E6.8C.81" title="cpp/utility">语言支持库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../concepts.html" title="cpp/concepts">概念库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../error.html" title="cpp/error">诊断库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../utility.html" title="cpp/utility">工具库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../string.html" title="cpp/string">字符串库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="https://zh.cppreference.com/w/cpp/container" title="cpp/container">容器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../iterator.html" title="cpp/iterator">迭代器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../ranges.html" title="cpp/ranges"> 范围库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../algorithm.html" title="cpp/algorithm">算法库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../numeric.html" title="cpp/numeric">数值库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../io.html" title="cpp/io">输入/输出库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../locale.html" title="cpp/locale">本地化库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../regex.html" title="cpp/regex">正则表达式库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../atomic.html" title="cpp/atomic">原子操作库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../thread.html" title="cpp/thread">线程支持库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../filesystem.html" title="cpp/filesystem">文件系统库</a> <span class="t-mark-rev t-since-cxx17">(C++17)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../experimental.html" title="cpp/experimental">技术规范</a> </td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../utility.html" title="cpp/utility">工具库</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="../../types.html" title="cpp/types">类型支持</a>（基本类型、 RTTI 、类型特性）</td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../memory.html" title="cpp/memory">动态内存管理</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../error.html" title="cpp/error">错误处理</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../program.html" title="cpp/utility/program">程序工具</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../variadic.html" title="cpp/utility/variadic">变参数函数</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../feature_test.html" title="cpp/utility/feature test">库特性测试宏</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../chrono.html" title="cpp/chrono">日期和时间</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../functional.html" title="cpp/utility/functional">函数对象</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../format.html" title="cpp/utility/format"> 格式化库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../initializer_list.html" title="cpp/utility/initializer list"><span class="t-lines"><span>initializer_list</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../source_location.html" title="cpp/utility/source location"><span class="t-lines"><span>source_location</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../bitset.html" title="cpp/utility/bitset"><span class="t-lines"><span>bitset</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../hash.html" title="cpp/utility/hash"><span class="t-lines"><span>hash</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../integer_sequence.html" title="cpp/utility/integer sequence"><span class="t-lines"><span>integer_sequence</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx14">(C++14)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 关系运算符 <span class="t-mark-rev t-deprecated-cxx20">(C++20 中弃用)</span> </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../rel_ops/operator_cmp.html" title="cpp/utility/rel ops/operator cmp"><span class="t-lines"><span>rel_ops::operator!=</span><span>rel_ops::operator&gt;</span><span>rel_ops::operator&lt;=</span><span>rel_ops::operator&gt;=</span></span></a></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 比较 <span class="t-mark-rev t-since-cxx20">(C++20)</span></td></tr><tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/three_way_comparable.html" title="cpp/utility/compare/three way comparable"><span class="t-lines"><span>three_way_comparable</span><span>three_way_comparable_with</span></span></a></div></div></td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/strong_ordering.html" title="cpp/utility/compare/strong ordering"><span class="t-lines"><span>strong_ordering</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/weak_ordering.html" title="cpp/utility/compare/weak ordering"><span class="t-lines"><span>weak_ordering</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/partial_ordering.html" title="cpp/utility/compare/partial ordering"><span class="t-lines"><span>partial_ordering</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/common_comparison_category.html" title="cpp/utility/compare/common comparison category"><span class="t-lines"><span>common_comparison_category</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_three_way_result.html" title="cpp/utility/compare/compare three way result"><span class="t-lines"><span>compare_three_way_result</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_three_way.html" title="cpp/utility/compare/compare three way"><span class="t-lines"><span>compare_three_way</span></span></a></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/strong_order.html" title="cpp/utility/compare/strong order"><span class="t-lines"><span>strong_order</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/weak_order.html" title="cpp/utility/compare/weak order"><span class="t-lines"><span>weak_order</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/partial_order.html" title="cpp/utility/compare/partial order"><span class="t-lines"><span>partial_order</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_strong_order_fallback.html" title="cpp/utility/compare/compare strong order fallback"><span class="t-lines"><span>compare_strong_order_fallback</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_weak_order_fallback.html" title="cpp/utility/compare/compare weak order fallback"><span class="t-lines"><span>compare_weak_order_fallback</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_partial_order_fallback.html" title="cpp/utility/compare/compare partial order fallback"><span class="t-lines"><span>compare_partial_order_fallback</span></span></a></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/named_comparison_functions.html" title="cpp/utility/compare/named comparison functions"><span class="t-lines"><span>is_eq</span><span>is_neq</span><span>is_lt</span><span>is_lteq</span><span>is_gt</span><span>is_gteq</span></span></a></div></div></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 共用词汇类型</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../pair.html" title="cpp/utility/pair"><span class="t-lines"><span>pair</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../tuple.html" title="cpp/utility/tuple"><span class="t-lines"><span>tuple</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../apply.html" title="cpp/utility/apply"><span class="t-lines"><span>apply</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../make_from_tuple.html" title="cpp/utility/make from tuple"><span class="t-lines"><span>make_from_tuple</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../optional.html" title="cpp/utility/optional"><span class="t-lines"><span>optional</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../any.html" title="cpp/utility/any"><span class="t-lines"><span>any</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../variant.html" title="cpp/utility/variant"><span class="t-lines"><span>variant</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"> <br>
</td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> swap 、 forward 与 move</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../../algorithm/swap.html" title="cpp/algorithm/swap"><span class="t-lines"><span>swap</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../exchange.html" title="cpp/utility/exchange"><span class="t-lines"><span>exchange</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx14">(C++14)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../forward.html" title="cpp/utility/forward"><span class="t-lines"><span>forward</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../move.html" title="cpp/utility/move"><span class="t-lines"><span>move</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../move_if_noexcept.html" title="cpp/utility/move if noexcept"><span class="t-lines"><span>move_if_noexcept</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 初等字符串转换</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../to_chars.html" title="cpp/utility/to chars"><span class="t-lines"><span>to_chars</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../from_chars.html" title="cpp/utility/from chars"><span class="t-lines"><span>from_chars</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../chars_format.html" title="cpp/utility/chars format"><span class="t-lines"><span>chars_format</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 类型运算</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../declval.html" title="cpp/utility/declval"><span class="t-lines"><span>declval</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../as_const.html" title="cpp/utility/as const"><span class="t-lines"><span>as_const</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../launder.html" title="cpp/utility/launder"><span class="t-lines"><span>launder</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../program.html" title="cpp/utility/program">程序支持工具</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h1"><td colspan="5"> 程序终止</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="abort.html" title="cpp/utility/program/abort"><span class="t-lines"><span>abort</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="exit.html" title="cpp/utility/program/exit"><span class="t-lines"><span>exit</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="quick_exit.html" title="cpp/utility/program/quick exit"><span class="t-lines"><span>quick_exit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="_Exit.html" title="cpp/utility/program/ Exit"><span class="t-lines"><span>_Exit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atexit.html" title="cpp/utility/program/atexit"><span class="t-lines"><span>atexit</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="at_quick_exit.html" title="cpp/utility/program/at quick exit"><span class="t-lines"><span>at_quick_exit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="EXIT_status.html" title="cpp/utility/program/EXIT status"><span class="t-lines"><span>EXIT_SUCCESS</span><span>EXIT_FAILURE</span></span></a></div></div></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 与环境交流</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="system.html" title="cpp/utility/program/system"><span class="t-lines"><span>system</span></span></a></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="getenv.html" title="cpp/utility/program/getenv"><span class="t-lines"><span>getenv</span></span></a></div></div></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 信号</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><strong class="selflink"><span class="t-lines"><span>signal</span></span></strong></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="raise.html" title="cpp/utility/program/raise"><span class="t-lines"><span>raise</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="sig_atomic_t.html" title="cpp/utility/program/sig atomic t"><span class="t-lines"><span>sig_atomic_t</span></span></a></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="SIG_strategies.html" title="cpp/utility/program/SIG strategies"><span class="t-lines"><span>SIG_DFL</span><span>SIG_IGN</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="SIG_ERR.html" title="cpp/utility/program/SIG ERR"><span class="t-lines"><span>SIG_ERR</span></span></a></div></div></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 信号类型</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="SIG_types.html" title="cpp/utility/program/SIG types"><span class="t-lines"><span>SIGABRT</span><span>SIGFPE</span><span>SIGILL</span><span>SIGINT</span><span>SIGSEGV</span><span>SIGTERM</span></span></a></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 非局部跳转</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="setjmp.html" title="cpp/utility/program/setjmp"><span class="t-lines"><span>setjmp</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="longjmp.html" title="cpp/utility/program/longjmp"><span class="t-lines"><span>longjmp</span></span></a></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 类型</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="jmp_buf.html" title="cpp/utility/program/jmp buf"><span class="t-lines"><span>jmp_buf</span></span></a></div></div></td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div></div>
<table class="t-dcl-begin"><tbody>
<tr class="t-dsc-header">
<td> <div>定义于头文件 <code><a href="../../header/csignal.html" title="cpp/header/csignal">&lt;csignal&gt;</a></code>
 </div></td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="coMULTI">/*signal-handler*/</span><span class="sy2">*</span> signal<span class="br0">(</span><span class="kw4">int</span> sig, <span class="coMULTI">/*signal-handler*/</span><span class="sy2">*</span> handler<span class="br0">)</span><span class="sy4">;</span></span></div></td>
<td> (1) </td>
<td class="t-dcl-nopad">  </td>
</tr>
<tr class="t-dcl">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="kw4">extern</span> <span class="st0">"C"</span> <span class="kw1">using</span> <span class="coMULTI">/*signal-handler*/</span> <span class="sy1">=</span> <span class="kw4">void</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// 仅为说明</span></span></div></td>
<td> (2) </td>
<td class="t-dcl-nopad">  </td>
</tr>
<tr class="t-dcl-sep"><td></td><td></td><td></td></tr>
</tbody></table>
<p>为信号 <code>sig</code> 设置处理函数。可设置信号处理函数以令默认处理发生、信号被忽略或用户定义函数得到调用。
</p><p>当信号处理函数被设为函数，且信号发生时，在信号处理函数开始之前是否立即执行 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">signal</span><span class="br0">(</span>sig, <a href="SIG_strategies.html"><span class="kw978">SIG_DFL</span></a><span class="br0">)</span></span></span> 是实现定义的。而且实现可以避免某些信号的实现定义集在信号处理函数运行时出现。
</p><p>对于某些信号，程序开始时是否调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">signal</span><span class="br0">(</span>sig, <a href="SIG_strategies.html"><span class="kw979">SIG_IGN</span></a><span class="br0">)</span></span></span> 所实现定义的。对于剩余函数，实现必须调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">signal</span><span class="br0">(</span>sig, <a href="SIG_strategies.html"><span class="kw978">SIG_DFL</span></a><span class="br0">)</span></span></span> 。
</p><p>（注意： POSIX 引入了 <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html">sigaction</a> 以标准化这些实现定义行为）
</p>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">参数</span></h3>
<table class="t-par-begin">


<tr class="t-par">
<td>  sig
</td>
<td> -
</td>
<td> 要设置信号处理函数的信号。它可以是实现定义值或下例值之一：
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="SIG_types.html" title="cpp/utility/program/SIG types"> <span class="t-lines"><span>SIGABRT</span><span>SIGFPE</span><span>SIGILL</span><span>SIGINT</span><span>SIGSEGV</span><span>SIGTERM</span></span></a></div></div>
</td>
<td>  定义信号类型 <br> <span class="t-mark">(宏常量)</span> </td></tr>
</table>
<p><br>
</p>
</td></tr>
<tr class="t-par">
<td>  handler
</td>
<td> -
</td>
<td> 信号处理函数。这必须是下列之一：
<ul><li><span class="t-lc"><a href="SIG_strategies.html" title="cpp/utility/program/SIG strategies">SIG_DFL</a></span> 宏。信号处理函数被设为默认信号处理函数。
</li><li><span class="t-lc"><a href="SIG_strategies.html" title="cpp/utility/program/SIG strategies">SIG_IGN</a></span> 宏。忽略信号。
</li><li>指向函数指针。函数签名必须等价于如下：
</li></ul>
<table class="t-dcl-begin"><tbody>

<tr class="t-dcl">
<td class="t-dcl-nopad"> <div><span class="mw-geshi cpp source-cpp"><span class="kw4">extern</span> <span class="st0">"C"</span> <span class="kw4">void</span> fun<span class="br0">(</span><span class="kw4">int</span> sig<span class="br0">)</span><span class="sy4">;</span></span></div></td>
<td class="t-dcl-nopad">  </td>
<td class="t-dcl-nopad">  </td>
</tr>
<tr class="t-dcl-sep"><td></td><td></td><td></td></tr>
</tbody></table>
</td></tr></table>
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">返回值</span></h3>
<p>成功时为先前的信号处理函数，失败时为 <span class="t-lc"><a href="SIG_ERR.html" title="cpp/utility/program/SIG ERR">SIG_ERR</a></span> （某些实现上能禁用设置信号处理函数）。
</p>
<h3><span class="mw-headline" id=".E4.BF.A1.E5.8F.B7.E5.A4.84.E7.90.86.E5.87.BD.E6.95.B0">信号处理函数</span></h3>
<p>下列限制被加诸被安装为信号处理函数的用户定义函数。
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-until-cxx17"><td>
<p>若信号处理函数不作为 <span class="t-lc"><a href="abort.html" title="cpp/utility/program/abort">std::abort</a></span> 或 <span class="t-lc"><a href="raise.html" title="cpp/utility/program/raise">std::raise</a></span> （异步信号）的结果调用，则行为未定义，若
</p>
<ul><li> 信号处理函数调用任何标准库中的函数，除了
</li></ul>
<dl><dd><ul><li> <span class="t-lc"><a href="abort.html" title="cpp/utility/program/abort">std::abort</a></span>
</li><li> <span class="t-lc"><a href="_Exit.html" title="cpp/utility/program/ Exit">std::_Exit</a></span>
</li><li> <span class="t-lc"><a href="quick_exit.html" title="cpp/utility/program/quick exit">std::quick_exit</a></span>
</li><li> <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">signal</span></span></span> ，以当前处理的信号的数字为首参数（异步处理函数能重注册其自身，但不能注册其他函数）。
</li></ul>
</dd></dl>
<ul><li> 信号处理函数涉及任何拥有静态或线程局域<span class="t-mark-rev t-since-cxx11">(C++11 起)</span>存储期的对象，且其类型不是 <span class="t-lc"><a href="../../atomic/atomic.html" title="cpp/atomic/atomic">std::atomic</a></span><span class="t-mark-rev t-since-cxx11">(C++11 起)</span> 或 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw977">std::<span class="me2">sig_atomic_t</span></span></a></span></span>.
</li></ul>
</td>
<td><span class="t-mark-rev t-until-cxx17">(C++17 前)</span></td></tr>
<tr class="t-rev t-since-cxx17"><td>
<p>若任何信号处理函数进行任何下列操作，则行为未定义：
</p>
<ul><li> 调用任何库函数，除了下列<i>信号安全</i>函数（注意，尤其是动态分配函数不是信号安全的）：
</li></ul>
<dl><dd><ul><li> <span class="t-lc"><a href="../../atomic/atomic.html" title="cpp/atomic/atomic">std::atomic</a></span> 的成员函数和来自 <a href="../../atomic.html" title="cpp/atomic">&lt;atomic&gt;</a> 的非成员函数，若它们所操作的原子类型是免锁的。函数 <span class="t-lc"><a href="../../atomic/atomic_is_lock_free.html" title="cpp/atomic/atomic is lock free">std::atomic_is_lock_free</a></span> 及 <span class="t-lc"><a href="../../atomic/atomic/is_lock_free.html" title="cpp/atomic/atomic/is lock free">std::atomic::is_lock_free</a></span> 对所有原子类型信号安全。
</li><li> <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">signal</span></span></span> ，以当前处理的信号的数字为首参数（异步处理函数能重注册其自身，但不能注册其他函数）。
</li><li> <span class="t-lc"><a href="../../types/numeric_limits.html" title="cpp/types/numeric limits">std::numeric_limits</a></span> 的函数
</li><li> <span class="t-lc"><a href="_Exit.html" title="cpp/utility/program/ Exit">std::_Exit</a></span>
</li><li> <span class="t-lc"><a href="abort.html" title="cpp/utility/program/abort">std::abort</a></span>
</li><li> <span class="t-lc"><a href="quick_exit.html" title="cpp/utility/program/quick exit">std::quick_exit</a></span>
</li><li> <span class="t-lc"><a href="../initializer_list.html" title="cpp/utility/initializer list">std::initializer_list</a></span> 的成员函数及 <span class="t-lc"><a href="../../iterator/begin.html" title="cpp/iterator/begin">std::begin</a></span> 与 <span class="t-lc"><a href="../../iterator/end.html" title="cpp/iterator/end">std::end</a></span> 的 <code>std::initializer_list</code> 重载 
</li><li> <span class="t-lc"><a href="../forward.html" title="cpp/utility/forward">std::forward</a></span> 、 <span class="t-lc">std::move</span> 、 <span class="t-lc"><a href="../move_if_noexcept.html" title="cpp/utility/move if noexcept">std::move_if_noexcept</a></span>
</li><li> 所有来自 <a href="../../types.html#.E7.B1.BB.E5.9E.8B.E7.89.B9.E6.80.A7" title="cpp/types">&lt;type_traits&gt;</a> 的函数
</li><li> <span class="t-lc"><a href="../../string/byte/memcpy.html" title="cpp/string/byte/memcpy">std::memcpy</a></span> 与 <span class="t-lc"><a href="../../string/byte/memmove.html" title="cpp/string/byte/memmove">std::memmove</a></span>
</li></ul>
</dd></dl>
<ul><li> 访问拥有线程存储期的对象
</li><li> <a href="../../language/dynamic_cast.html" title="cpp/language/dynamic cast"><tt>dynamic_cast</tt></a> 表达式
</li><li> <a href="../../language/throw.html" title="cpp/language/throw"><tt>throw</tt></a> 表达式
</li><li> 进入 <a href="../../language/try_catch.html" title="cpp/language/try catch"><tt>try</tt></a> 块，包含<a href="../../language/function-try-block.html" title="cpp/language/function-try-block"><tt>函数 try 块</tt></a>
</li><li> 初始化进行<a href="../../language/initialization.html#.E9.9D.9E.E5.B1.80.E9.83.A8.E5.8F.98.E9.87.8F" title="cpp/language/initialization">动态非局部初始化</a>的静态变量（包含延迟直至首次 ODR 使用者）
</li><li> 等待任何有静态存储期变量的初始化完成，由于另一线程共时初始化之
</li></ul>
</td>
<td><span class="t-mark-rev t-since-cxx17">(C++17 起)</span></td></tr>
</table>
<p>若在处理 <span class="t-lc"><a href="SIG_types.html" title="cpp/utility/program/SIG types">SIGFPE</a></span> 、 <span class="t-lc"><a href="SIG_types.html" title="cpp/utility/program/SIG types">SIGILL</a></span> 、 <span class="t-lc"><a href="SIG_types.html" title="cpp/utility/program/SIG types">SIGSEGV</a></span> 或任何实现定义的指定计算性异常的其他信号时，用户定义函数返回，则行为未定义。
</p><p>若信号处理函数作为 <span class="t-lc"><a href="abort.html" title="cpp/utility/program/abort">std::abort</a></span> 或 <span class="t-lc"><a href="raise.html" title="cpp/utility/program/raise">std::raise</a></span> （异步调用）的结果调用，则行为未定义，若信号处理函数调用 <span class="t-lc"><a href="raise.html" title="cpp/utility/program/raise">std::raise</a></span> 。
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-until-cxx14"><td>
<p>在信号处理函数入口，<a href="../../numeric/fenv.html" title="cpp/numeric/fenv">浮点环境</a>的状态和所有对象的值都是未指定的，除了
</p>
<ul><li> <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw977">std::<span class="me2">sig_atomic_t</span></span></a></span></span> 类型对象
</li><li> 无锁 <span class="t-lc"><a href="../../atomic/atomic.html" title="cpp/atomic/atomic">std::atomic</a></span> 类型对象<span class="t-mark-rev t-since-cxx11">(C++11 起)</span>
</li><li> 通过 <span class="t-lc"><a href="../../atomic/atomic_signal_fence.html" title="cpp/atomic/atomic signal fence">std::atomic_signal_fence</a></span> 设为可见的副效应<span class="t-mark-rev t-since-cxx11">(C++11 起)</span>
</li></ul>
<p>从信号处理函数返回时，任何信号处理函数所修改的，非 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw977">std::<span class="me2">sig_atomic_t</span></span></a></span></span> 或免锁 <span class="t-lc"><a href="../../atomic/atomic.html" title="cpp/atomic/atomic">std::atomic</a></span> 对象的值是不确定的。
</p>
</td>
<td><span class="t-mark-rev t-until-cxx14">(C++14 前)</span></td></tr>
<tr class="t-rev t-since-cxx14"><td>
<p>对函数 <code>signal()</code> 的调用<a href="../../atomic/memory_order.html" title="cpp/atomic/memory order">同步于</a>任何信号处理函数调用的结果。
</p><p>若信号处理函数作为到 <span class="t-lc"><a href="raise.html" title="cpp/utility/program/raise">std::raise</a></span> （同步）的调用结果执行，则处理函数的执行<i>后序于</i> <code>std::raise</code> 的调用并<i>先序于</i>从它返回，并与 <span class="t-lc">std::raise</span> 运行于同一线程。其他信号处理函数的执行对于程序其余部分是<i>无序</i>的，并且运行于未指定的线程。
</p><p>若对同一 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw977">std::<span class="me2">sig_atomic_t</span></span></a></span></span> 类型对象的二次访问出现于同一线程，则它们不导致数据竞争，即使在信号处理函数中出现一或多次。
对每次信号处理函数调用，调用信号处理函数的线程所进行的求值可分为二组 A 与 B ，满足 B 中无求值<i>先发生于</i> A 中的求值，且这种 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw977">std::<span class="me2">sig_atomic_t</span></span></a></span></span> 对象的求值采用该值，如同 A 中所有求值<a href="../../atomic/memory_order.html" title="cpp/atomic/memory order">先发生于</a>信号函数的执行，且信号函数的求值<i>先发生于</i> B 中所有求值。
</p>
</td>
<td><span class="t-mark-rev t-since-cxx14">(C++14 起)</span></td></tr>
</table>
<h3><span class="mw-headline" id=".E6.B3.A8.E6.84.8F">注意</span></h3>
<p>POSIX 要求 <code>signal</code> 为线程安全，且<a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04">指定一个异步信号安全库函数的列表</a>，它们能从任何信号处理函数调用。
</p><p>信号处理函数被期待拥有 <a href="../../language/language_linkage.html" title="cpp/language/language linkage">C 链接</a>，而且通常只使用 C 与 C++ 的公共子集。拥有 C++ 链接的函数能否用作信号处理函数是实现定义的。
</p>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">示例</span></h3>
<div class="t-example"><div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">运行此代码</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="co2">#include &lt;csignal&gt;</span>
<span class="co2">#include &lt;iostream&gt;</span>
 
<span class="kw1">namespace</span>
<span class="br0">{</span>
  <span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw977">std::<span class="me2">sig_atomic_t</span></span></a> gSignalStatus<span class="sy4">;</span>
<span class="br0">}</span>
 
<span class="kw4">void</span> signal_handler<span class="br0">(</span><span class="kw4">int</span> signal<span class="br0">)</span>
<span class="br0">{</span>
  gSignalStatus <span class="sy1">=</span> signal<span class="sy4">;</span>
<span class="br0">}</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
  <span class="co1">// 安装信号处理函数</span>
  std<span class="sy4">::</span><span class="me2">signal</span><span class="br0">(</span><a href="SIG_types.html"><span class="kw984">SIGINT</span></a>, signal_handler<span class="br0">)</span><span class="sy4">;</span>
 
  <a href="../../io/cout.html"><span class="kw1757">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">"SignalValue: "</span> <span class="sy1">&lt;&lt;</span> gSignalStatus <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span>
  <a href="../../io/cout.html"><span class="kw1757">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">"Sending signal "</span> <span class="sy1">&lt;&lt;</span> <a href="SIG_types.html"><span class="kw984">SIGINT</span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span>
  <a href="raise.html"><span class="kw976">std::<span class="me2">raise</span></span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw984">SIGINT</span></a><span class="br0">)</span><span class="sy4">;</span>
  <a href="../../io/cout.html"><span class="kw1757">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">"SignalValue: "</span> <span class="sy1">&lt;&lt;</span> gSignalStatus <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>可能的输出：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">SignalValue: 0
Sending signal 2
SignalValue: 2</pre></div></div> 
</div>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="raise.html" title="cpp/utility/program/raise"> <span class="t-lines"><span>raise</span></span></a></div></div>
</td>
<td>  为特定信号运行信号处理函数 <br> <span class="t-mark">(函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../atomic/atomic_signal_fence.html" title="cpp/atomic/atomic signal fence"> <span class="t-lines"><span>atomic_signal_fence</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div>
</td>
<td>  线程与执行于同一线程的信号处理函数间的栅栏 <br> <span class="t-mark">(函数)</span> </td></tr>

</table>

<!-- 
NewPP limit report
Preprocessor visited node count: 6431/1000000
Preprocessor generated node count: 12220/1000000
Post‐expand include size: 179422/2097152 bytes
Template argument size: 43750/2097152 bytes
Highest expansion depth: 21/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_zh_:pcache:idhash:848-0!*!0!!zh!*!zh!* and timestamp 20200113061337 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    来自“<a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/utility/program/signal&amp;oldid=53471">https://zh.cppreference.com/mwiki/index.php?title=cpp/utility/program/signal&amp;oldid=53471</a>”                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        <div id="cpp-footer-base" class="noprint">
            <div id="footer">
                        <div id="cpp-navigation">
            <h5>导航</h5>
            <ul><li><a href="https://zh.cppreference.com/w/cpp/utility/program/signal">Online version</a></li><li>Offline version retrieved 2020-03-14 18:00.</li></ul></div>
                        <ul id="footer-info">
                                    <li id="footer-info-lastmod"> 本页面最后修改于2018年3月5日 (星期一) 20:19。</li>
                                    <li id="footer-info-viewcount">此页面已被浏览过12,314次。</li>
                            </ul>
                    </div>
        </div>
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.MathJax","ext.gadget.ColiruCompiler"], null, true);
}</script>
<script src="../../../../common/site_scripts.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 1.746 secs. -->
	</body>
<!-- Cached 20200113061337 -->
</html>